﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LiveFX.Client;
using System.Windows.Forms;

namespace LiveFrameworkExplorer.Plugins
{
    public class DeleteLiveItemPlugin : IPlugin, IPluginItem
    {
        private ILFEBase _lfeBase = null;

        #region IPlugin Members

        public void Init(ILFEBase lfeBase)
        {
            _lfeBase = lfeBase;
        }

        public List<Type> GetTypes()
        {
            return new List<Type>() { 
                typeof(LiveItem)
            };
        }

        public string GetMenuItemLabel()
        {
            return "Delete";
        }

        public System.Drawing.Image GetMenuItemImage()
        {
            return LiveFrameworkExplorer.Properties.Resources.Delete;
        }

        public bool CheckItem<TMeshItem, TResource>(object item)
            where TMeshItem : Microsoft.LiveFX.Client.LiveItem<TResource>, new()
            where TResource : Microsoft.LiveFX.ResourceModel.Resource, new()
        {
            return true;
        }

        public void OpenPlugin<TMeshItem, TResource>(object item, object parentItem)
            where TMeshItem : Microsoft.LiveFX.Client.LiveItem<TResource>, new()
            where TResource : Microsoft.LiveFX.ResourceModel.Resource, new()
        {
            var lvieItem = item as TMeshItem;
            var collection = parentItem as LiveItemCollection<TMeshItem, TResource>;
            if (collection != null)
            {
                if (MessageBox.Show("Are you sure to delete this live item ?", "Live Framework Explorer",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    collection.Remove(lvieItem);
                    MessageBox.Show("The live item has been deleted !", "Live Framework Explorer",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //_lfeBase.ReloadLFE();
                    _lfeBase.Refresh<TMeshItem, TResource>();
                }
            }
        }

        #endregion
    }
}
